package com.red.service.impl;

import com.red.entity.Order;
import com.red.mapper.OrderMapper;
import com.red.service.OrderService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderServiceImpl extends Service implements OrderService {
    private OrderMapper mapper;

    public OrderServiceImpl() {
        mapper = session.getMapper(OrderMapper.class);
    }

    public int createOrder(int house_id, int uID) {
        HashMap<String, Integer> param = new HashMap<String, Integer>();
        param.put("uID", uID);
        param.put("house_id", house_id);
        mapper.insertOrder(param);

        destroy();

        return param.get("result");
    }

    public List<Map<String, String>> queryOrder(int uID) {
        List<Map<String, String>> orders = mapper.selectOrderByUser(uID);
        destroy();
        return orders;
    }

    public int updateOrder(Order order) {
        int result = mapper.updateOrder(order);
        destroy();
        return result;
    }

    public void pay(int order_id){
        mapper.pay(order_id);
        destroy();
    }

    public void deleteOrder(int order_id){
        mapper.deleteOrder(order_id);
        destroy();
    }

    public void giveupOrder(int order_id){
        mapper.giveupOrder(order_id);
        destroy();
    }
}
